<template>
  <div class="project-index-container container">
    <div class="query-container lin-flex lin-flex-between">
      <div class="left-panel">
        <router-link :to="{name: 'ProjectCreate'}">
          <el-button type="primary" icon="el-icon-plus" size="small">添加</el-button>
        </router-link>
      </div>

      <div class="right-panel lin-flex">
        <el-input placeholder="请输入搜索内容" size="small" />
        <el-button type="primary" icon="el-icon-search" size="small" style="margin-left: 10px" @click="onSearchProject">
          查询
        </el-button>
      </div>
    </div>

    <div class="project-table">
      <el-table
        :data="projectList"
        border
        fit
        highlight-current-row
      >
        <el-table-column label="Order No">
          <template slot-scope="scope">
            {{ scope.row.OrderNo }}
          </template>
        </el-table-column>
        <el-table-column label="Project No">
          <template slot-scope="scope">
            {{ scope.row.ProjectNo }}
          </template>
        </el-table-column>
        <el-table-column label="Order Type">
          <template slot-scope="scope">
            {{ scope.row.OrderType }}
          </template>
        </el-table-column>
        <el-table-column label="Applicant">
          <template slot-scope="scope">
            {{ scope.row.Applicant }}
          </template>
        </el-table-column>
        <el-table-column label="Deadline">
          <template slot-scope="scope">
            {{ scope.row.TimeMs.Deadline }}
          </template>
        </el-table-column>
        <el-table-column label="Amount">
          <template slot-scope="scope">
            {{ scope.row.Amount }}
          </template>
        </el-table-column>
        <el-table-column label="Status">
          <template slot-scope="scope">
            {{ scope.row.Status }}
          </template>
        </el-table-column>
        <el-table-column label="Action">
          <template slot-scope="scope">
            <el-link type="primary" @click="onEditProject(scope.row)">Edit</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { fetchProjectList } from '@/api/project'

export default {
  name: 'ProjectIndex',
  data() {
    return {
      projectList: [],
      projectCount: 0,
      listQuery: {
        Page: 1,
        PageSize: 10
      }
    }
  },
  created() {
    this.fetchList()
  },
  methods: {
    async fetchList() {
      const data = await fetchProjectList(this.listQuery)
      this.projectList = data.Data
      this.projectCount = data.Count
    },
    onSearchProject() {},
    onEditProject(row) {
      this.$router.push({ name: 'ProjectEdit', query: { id: row.Id }})
    }
  }
}
</script>

<style lang="scss" scoped>
.project-table {
  margin-top: 10px;
}
</style>
